package com.pcl.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * @author long
 * @date 2013-5-2 ����1:33:49
 * @qq 108232706
 * @description DBMgr
 */
public class DBMgr {

	public final int index;
	public static final Properties dbProps = new Properties();
	private Connection connection;

	public Connection Open() {
		return connection;
	}

	public int state() {
		try {
			initDataBases();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return index;
	}

	public DBMgr(int _index) throws Throwable {
		this.index = _index;
		//		initDataBases();
	}

	/**
	 * ��ʼ��������ݿ�����
	 * 
	 * @throws Throwable
	 */
	private void initDataBases() throws Throwable {
		connection = initConnectionByName();
	}

	private Connection initConnectionByName() throws Throwable {

		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			throw new Throwable("��ʼ����ݿ����ӳش���" + e);
		}
		try {
			// ���ó�ʱ
			// DriverManager.setLoginTimeout(30);
			return DriverManager.getConnection("jdbc:mysql://192.168.0.144:3306/Mutil_TexasPoker?useUnicode=true&amp;characterEncoding=GBK", "long", "1234");
		} catch (Exception e) {
			throw e;
		} finally {

		}

	}
	public Connection initConnectionByName1() throws Throwable {

		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			throw new Throwable("111" + e);
		}
		try {
			return DriverManager.getConnection("jdbc:mysql://192.168.0.144:3306/Mutil_TexasPoker?useUnicode=true&amp;characterEncoding=GBK", "long", "1234");
		} catch (Exception e) {
			throw e;
		} finally {

		}

	}
}
